//
//  DHLeftBarTopView.m
//  DHKuaiYi
//
//  Created by Cedric Zheng on 13/11/2016.
//  Copyright © 2016 30-陈辉华. All rights reserved.
//

#import "DHLeftBarTopView.h"
#import <Masonry.h>

#define ICON_HW self.xhh_height*0.6

@implementation DHLeftBarTopView

#pragma mark - Life Cycle
- (void)xhhSetupSubviews {
    [super xhhSetupSubviews];
    
//        self.hasLogin = YES;
    
    self.backgroundColor = [UIColor globalColor];
    
    //    icon.userInteractionEnabled = NO;
    
    [self.icon setImage:[UIImage imageNamed:@"icon_bb"] forState:UIControlStateNormal];
    //切圆形图像
    self.icon.layer.masksToBounds = YES;
    self.icon.layer.cornerRadius = ICON_HW * 0.5;
    [self addSubview:self.icon];
    
    [self.userNameOrLogin setTitle:@"用户名或者登陆" forState:UIControlStateNormal];
    self.userNameOrLogin.titleLabel.textColor = [UIColor blackColor];
    [self addSubview:self.userNameOrLogin];
    
    [self.basicInfoOrRegister setTitle:@"基础信息或者注册" forState:UIControlStateNormal];
    [self addSubview:self.basicInfoOrRegister];
}

#pragma mark - Events

#pragma mark – Private Methods

/**
 重写layoutSubviews方法
 */
- (void)layoutSubviews {
    [super layoutSubviews];
    
    if (self.hasLogin) {
        
        

        [self.icon mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.width.equalTo(self.mas_height).multipliedBy(0.6);
            make.top.equalTo(self).offset(25);
            make.leading.equalTo(self).offset(12);
        }];
        
        [self.userNameOrLogin mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.icon);
            make.leading.equalTo(self.icon.mas_trailing).offset(8);
        }];
        
        [self.basicInfoOrRegister mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.icon);
            make.leading.equalTo(self.icon.mas_trailing).offset(8);
        }];
        
    } else {
        
        [self.icon mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.height.width.equalTo(self.mas_height).multipliedBy(0.6);
            make.center.equalTo(self);
        }];
        
        [self.userNameOrLogin mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.icon);
            make.right.equalTo(self.icon.mas_left).offset(-8.0);
            make.left.equalTo(self).offset(8.0);
        }];
        
        [self.basicInfoOrRegister mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.icon);
            make.left.equalTo(self.icon.mas_right).offset(8.0);
            make.right.equalTo(self).offset(-8.0);
        }];
    }
}

#pragma mark - <#Delegates#>

#pragma mark - <#Datasources#>

#pragma mark – Getters and Setters
- (UIButton *)icon {
    if (!_icon) {
        _icon = [UIButton new];
    }
    return _icon;
}

- (UIButton *)userNameOrLogin {
    if (!_userNameOrLogin) {
        _userNameOrLogin = [UIButton new];
    }
    return _userNameOrLogin;
}

- (UIButton *)basicInfoOrRegister {
    if (!_basicInfoOrRegister) {
        _basicInfoOrRegister = [UIButton new];
    }
    return _basicInfoOrRegister;
}

@end
